package cn.ybk.basic.service.impl;

import cn.ybk.basic.service.VerifyCodeService;
import cn.ybk.basic.util.VerifyCodeUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.util.concurrent.TimeUnit;

@Service
public class VerifyCodeServiceImpl implements VerifyCodeService {

    @Autowired
    private RedisTemplate redisTemplate;

    @Override
    public String verifyCode(String imageCodeKey) throws IOException {
        // 发送验证码
        String verify = VerifyCodeUtils.generateVerifyCode(4);
        // 存入redis中
        redisTemplate.opsForValue().set(imageCodeKey,verify,3, TimeUnit.MINUTES);
        // 返回编码
        return VerifyCodeUtils.VerifyCode(115 , 40, verify);

    }

    @Override
    public String verifyEmailCode(String emailImageCodeKey) throws IOException  {
        // 发送验证码
        String verify = VerifyCodeUtils.generateVerifyCode(4);
        // 存入redis中
        redisTemplate.opsForValue().set(emailImageCodeKey,verify,3, TimeUnit.MINUTES);
        // 返回编码
        return VerifyCodeUtils.VerifyCode(115 , 40, verify);
    }
}
